<?php echo link_to('жагсаалт', 'season/index', array('class'=>'title'))?> 
<span class="separator"> | </span>
<?php echo link_to('шинээр нэмэх', 'season/new', array('class'=>'title'))?>
<br clear="all">
<br clear="all">

<?php use_stylesheets_for_form($form) ?>
<?php use_javascripts_for_form($form) ?>

<form action="<?php echo url_for('season/'.($form->getObject()->isNew() ? 'create' : 'update').(!$form->getObject()->isNew() ? '?s_id='.$form->getObject()->getSId() : '')) ?>" method="post" <?php $form->isMultipart() and print 'enctype="multipart/form-data" ' ?>>
<?php if (!$form->getObject()->isNew()): ?>
<input type="hidden" name="sf_method" value="put" />
<?php endif; ?>
  <table>
    <tfoot>
      <tr>
        <td colspan="2">
          <?php echo $form->renderHiddenFields(false) ?>
          &nbsp;<a href="<?php echo url_for('season/index') ?>">Back to list</a>
          <?php if (!$form->getObject()->isNew()): ?>
            &nbsp;<?php echo link_to('Delete', 'season/delete?s_id='.$form->getObject()->getSId(), array('method' => 'delete', 'confirm' => 'Are you sure?')) ?>
          <?php endif; ?>
          <input type="submit" value="Save" />
        </td>
      </tr>
    </tfoot>
    <tbody>
      <?php echo $form->renderGlobalErrors() ?>
      <tr>
        <th><?php echo $form['s_name']->renderLabel() ?></th>
        <td>
          <?php echo $form['s_name']->renderError() ?>
          <?php echo $form['s_name'] ?>
        </td>
      </tr>
      <tr>
        <th><?php echo $form['s_descr']->renderLabel() ?></th>
        <td>
          <?php echo $form['s_descr']->renderError() ?>
          <?php echo $form['s_descr'] ?>
        </td>
      </tr>      
      <tr>
        <th><?php echo $form['l_id']->renderLabel() ?></th>
        <td>
          <?php echo $form['l_id']->renderError() ?>
          <?php echo $form['l_id'] ?>
        </td>
      </tr>
      <tr>
        <th><?php echo $form['published']->renderLabel() ?></th>
        <td>
          <?php echo $form['published']->renderError() ?>
          <?php echo $form['published'] ?>
        </td>
      </tr>
      <tr>
        <th><?php echo $form['s_win_point']->renderLabel() ?></th>
        <td>
          <?php echo $form['s_win_point']->renderError() ?>
          <?php echo $form['s_win_point'] ?>
        </td>
      </tr>
      <tr>
        <th><?php echo $form['s_lost_point']->renderLabel() ?></th>
        <td>
          <?php echo $form['s_lost_point']->renderError() ?>
          <?php echo $form['s_lost_point'] ?>
        </td>
      </tr>
      
      <tr>
        <th>Багууд <a name="teams">&nbsp;</a></th>
        <td>
          <?php $existingTeamIds = Doctrine::getTable('BbSeasonTeams')->getTeamIds($form->getObject()->getSId()); ?>
          <?php $teams = Doctrine::getTable('BbTeams')->createQuery('a')->execute(); ?>
          <label style="font-weight:normal;text-align:left;border-bottom:1px solid #bbb;width:250px;">
              <input type="checkbox" id="checker" onclick="toggleChecked(this.checked);"/> Бүгд
          </label>
          <?php foreach ($teams as $team): ?>
              <label style="font-weight:normal;text-align:left;">
                  <input type="checkbox" <?php echo in_array($team->getId(), $existingTeamIds) ? 'checked' : ''?> class="checkbox" name="team_ids[]" value="<?php echo $team->getId()?>"/>
                  <?php echo $team?>
              </label>
          <?php endforeach ?>
        </td>
      </tr>
      
    </tbody>
  </table>
</form>

<script type="text/javascript">
function toggleChecked(status) {
  $(".checkbox").each( function() {
    $(this).attr("checked",status);
  });
}
</script>